package action;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.Department;
import bean.Employee;
import bean.Plan;
import biz.DepartmentBiz;
import biz.EmployeeBiz;
import biz.PlanBiz;
import biz.impl.DepartmentBizImpl;
import biz.impl.EmployeeBizImpl;
import biz.impl.PlanBizImpl;

public class PlanaddAction extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String page = "";
		HttpSession session = request.getSession(false);
		if (session == null){
			response.sendRedirect("/login.jsp");
		}
		request.setCharacterEncoding("gbk");
		String content=request.getParameter("content");
		String startDate=request.getParameter("startDate");
		String endDate=request.getParameter("endDate");
		String completestate=request.getParameter("completeState");
		int eid=Integer.parseInt(request.getParameter("eid"));
		int depId=Integer.parseInt(request.getParameter("depId"));
		PlanBiz pb=new PlanBizImpl();
		DepartmentBiz db=new DepartmentBizImpl();
		EmployeeBiz eb=new EmployeeBizImpl();
		Plan plan=new Plan();
		Employee emp=eb.getEmployeeByeid(eid);
		Department department=db.getDepartmentBydepId(depId);
		plan.setCompletestate(completestate);
		plan.setContent(content);
		plan.setDepartment(department);
		plan.setEmployee(emp);
		plan.setEnddate(endDate);
		plan.setStartdate(new Date(startDate));
		boolean success=pb.save(plan);
		if(success==true){
			response.sendRedirect("PlansearchAction");
		}else{
			response.sendRedirect("add_plan.jsp");
		}
	}
}
